package com.jochen.core.assets

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.assets.AssetDescriptor
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture.TextureFilter

enum class FontAsset(
    private val fontName: String,
    private val size: Int,
    private val color: Color
) : Asset<BitmapFont> {

    MAIN_FONT("font.ttf", 16, Color.WHITE);

    override lateinit var descriptor: AssetDescriptor<BitmapFont>

    init {
        descriptor = FreetypeFontLoader.FreeTypeFontLoaderParameter().run {
            fontFileName = "fonts/$fontName"
            fontParameters.apply {
                this.size = (this@FontAsset.size * Gdx.graphics.density).toInt()
                characters = FreeTypeFontGenerator.DEFAULT_CHARS
                this.color = this@FontAsset.color
                incremental = true
                genMipMaps = true
                minFilter = TextureFilter.MipMapLinearLinear
                magFilter = TextureFilter.Linear
                hinting = FreeTypeFontGenerator.Hinting.AutoFull
            }
            AssetDescriptor(fontFileName, BitmapFont::class.java, this)
        }
    }
}